# 绝对引用，使我们的celery模块不会与原始的celery冲突
from __future__ import absolute_import, unicode_literals
# 导入原始的celery模块中shared_task    from xx import xx
from celery import shared_task
# 使用django内置函数发送邮件
from django.core.mail import send_mail
# 导入django的settings
from django.conf import settings
from workorder.celery import app

@app.task
def send_mail_task(username, email, user_id):
    """
    使用django内置函数发送邮件
    """
    subject = '工单系统找回密码'  # 主题
    message = ''  # 文本消息
    from_email = settings.EMAIL_FROM
    recipient_list = [email]

    html_message = '<h3>您好{}，欢迎来到工单系统找回密码！请点击以下链接进行激活：</br>< a href="http://127.0.0.1:8080/Update">点击修改密码</ a></h3>'.format(
        username, user_id)

    send_mail(
        subject=subject,
        message=message,
        from_email=from_email,
        recipient_list=recipient_list,
        html_message=html_message
    )

# celery -A workorder worker -l info -P eventlet